/**
 * @Author:卿雨欣
 * @Date:2020/7/3
 * @Description:这是产品买入页面
 */
import React,{Component} from "react";
import NavBuyIn from "./Components_BuyIn/NavBuyIn";
import CardBuyIn from "./Components_BuyIn/CardBuyIn";
import {WhiteSpace} from "antd-mobile";
import { createForm } from 'rc-form';
import FormBuyIn from './Components_BuyIn/FormBuyIn'
import axios from "axios";
import {URL} from "../../index";
const FormBuyInWrapper = createForm()(FormBuyIn);
// 将获取的数据中属性为数字的转换为文字
function comBaseCateName(comBaseCate){
    //修改组合产品类型
    switch (comBaseCate) {
        case 1:
            comBaseCate = "股票型";
            break;
        case 2:
            comBaseCate = "基金型";
            break;
        case 3:
            comBaseCate = "混合型";
            break;
    }

   return comBaseCate;
}
function comBaseRiskLevel(comBaseRiskLevel){
    //修改组合产品风险等级
    switch (comBaseRiskLevel) {
        case 1:
            comBaseRiskLevel ="谨慎型";
            break;
        case 2:
            comBaseRiskLevel ="稳健型";
            break;
        case 3:
            comBaseRiskLevel ="平衡型";
            break;
        case 4:
            comBaseRiskLevel ="进取型";
            break;
        default:
            comBaseRiskLevel ="激进型";
            break;
    }
    return comBaseRiskLevel;
}
export default class BuyIn extends Component{
    constructor(props) {
        super(props);
        const comBaseId=this.props.location.state.comBaseId
        const comBaseName=this.props.location.state.comBaseName
        const conBaseStartMoney=this.props.location.state.conBaseStartMoney
        const comBaseCate=this.props.location.state.comBaseCate
        const comBaseRiskLevel=this.props.location.state.comBaseRiskLevel
        this.state={
            comBaseId:comBaseId,//组合id
            comBaseName:comBaseName,//组合名称
            conBaseStartMoney:conBaseStartMoney,//起投金额
            comBaseCate:comBaseCate,//组合类别
            comBaseRiskLevel:comBaseRiskLevel//组合风险等级
        }
    }
    componentWillMount() {
        axios({
            method:"GET",
            url: URL + "/combinationBaseInfo/getCombinationBaseInfoEntity",
            params: {
                comBaseId:this.props.location.state.comBaseId
            }
        }).then(res => {
            if (res.data.code === 200) {
                this.setState({
                    conBaseStartMoney:res.data.combination.conBaseStartMoney,
                    comBaseCate:comBaseCateName(res.data.combination.comBaseCate),
                    comBaseRiskLevel:comBaseRiskLevel(res.data.combination.comBaseRiskLevel),
                })
            }else{
                console.log(res.data)
                console.log(this.state.comBaseName)
            }
        })
    }
    render(){
        return(
            <div>
                <NavBuyIn/>
                <WhiteSpace size='lg'/>
                <WhiteSpace size='lg'/>
                <WhiteSpace size='lg'/>
                <CardBuyIn  comBaseName={this.state.comBaseName}
                            comBaseCate={this.state.comBaseCate}
                />
                <WhiteSpace size='lg'/>
                <FormBuyInWrapper
                    comBaseId={this.state.comBaseId}
                    comBaseName={this.state.comBaseName}
                    conBaseStartMoney={this.state.conBaseStartMoney}
                    comBaseCate={this.state.comBaseCate}
                    comBaseRiskLevel={this.state.comBaseRiskLevel}
                    history={this.props.history}
                />
            </div>
        )
    }
}